package top.kaoshanji.p3ch04a;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import top.kaoshanji.p3ch04a.mapper.TeacherMapper;
import top.kaoshanji.p3ch04a.model.Teacher;
import top.kaoshanji.p3ch04a.util.SqlSessionUtil;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/20 10:41
 */
public class TeacherMapperTest {

    /**
     * 代码清单test-p3ch04a-107页a：根据教师id查询教师和学生（collection标签之关联嵌套映射）
     */
    @Test
    public void testGetTeacherByID1() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            TeacherMapper teacherMapper = sqlSession.getMapper(TeacherMapper.class);

            Teacher teacher = teacherMapper.getTeacherByID1(1);
            System.out.println(teacher);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }

    }


    /**
     * 代码清单test-p3ch04a-109页a：根据教师id查询教师和学生（collection标签之关联嵌套查询）
     */
    @Test
    public void testGetTeacherByID2() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            TeacherMapper teacherMapper = sqlSession.getMapper(TeacherMapper.class);

            Teacher teacher = teacherMapper.getTeacherByID2(1);
            System.out.println(teacher);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }

    }



}
